<template>
  <div>
    <van-dropdown-menu>
      <van-dropdown-item
        v-model="value1"
        :options="option1"
        title="综合"
        disabled
      />

      <van-dropdown-item v-model="value1" :options="option1" title="价格" @change="priceChange"/>

      <van-dropdown-item
        v-model="value2"
        :options="filterCategory"
        title="分类"
        @change="categoryChange"
      />
    </van-dropdown-menu>

      <!-- 如果没有产品 products就不展示 而要展示Empty组件 -->
      <van-empty v-if="productsListData.length==0" description="没有这类商品" />
    <Products v-else :productsListData="productsListData" />
  </div>
</template>

<script>
import Products from "../Products.vue";

export default {
  props: ["productsListData", "filterCategory"],
  components: {
    Products,
  },
  methods: {
    categoryChange(value) {
      // console.log("选中了", value);
      this.$emit("categoryChange", value); //其实value 就是分类ID
    }, 
    priceChange(value){
      this.$emit("priceChange",value)
      // console.log(value);
    }
  },
  // 需求:正确的勾选上分类中的某一项:要把value2做活了.value2当值必须为filterCategory这个数组中的chcecked为true的这一项
  beforeUpdate() {
    // this.value2
    this.filterCategory.map((item) => {
      if (item.checked) {
        this.value2 = item.value;
      }
    });
  },
  data() {
    return {
      value1: "", //为了一开始不是顺序排序,所以给初始值为空
      value2: 1010000,
      option1: [
        { text: "价格由高到低", value: "desc" },
        { text: "价格由低到高", value: "asc" },
      ],
      // option2: [
      //   { text: "全部", value: "a" },
      //   { text: "居家", value: "b" },
      // ],
    
    };
  },
};
</script>
 
<style lang = "less" scoped>
</style>